home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / afloat.zip / FCMP.ASM < prev    next >
Assembly Source File  |  1988-03-17  |  1KB  |  71 lines

  1.        PAGE ,132
  2. ;----------------------------------------------------------
  3. ; FCMP -- version for use with assembly language programs
  4. ;
  5. ; Copyright Bob Kline 1988
  6. ;
  7. ; Purpose:
  8. ;       Compare two floating-point values to see which is
  9. ;       larger.
  10. ;
  11. ; Input:
  12. ;       4-byte real in DX:AX and 4-byte real in CX:BX
  13. ;
  14. ; Output:
  15. ;       AX contains positive integer if first value is
  16. ;       greater, negative integer if first is smaller,
  17. ;       0 if values equal.
  18. ;
  19. ; Other registers affected:
  20. ;    DX, CX, BX, SI
  21. ;
  22. ; Other procedures called:
  23. ;       none
  24. ;----------------------------------------------------------
  25.         PUBLIC  FCMP
  26.  
  27.     .MODEL    SMALL
  28.  
  29.     .CODE
  30.  
  31. FCMP        PROC
  32.  
  33. ; see if the signs are different
  34.         PUSH    DX
  35.         PUSH    CX
  36.         AND     DX,8000h
  37.         AND     CX,8000h
  38.         CMP     DX,CX
  39.         POP     CX
  40.         POP     DX
  41.     JE    SAME_SIGN
  42.         JG      SKIP1
  43.         MOV     AX,-1
  44.         RET
  45. SKIP1:  MOV     AX,1
  46.         RET
  47.  
  48. ; if we're here, the signs must have been the same
  49. ;   save the sign and try the rest of the numbers
  50. SAME_SIGN:
  51.     MOV    SI,DX
  52.     AND    SI,8000h
  53.     PUSH    SI
  54.     SUB    DX,CX
  55.     JE    LOW_CHECK
  56.     XCHG    DX,AX
  57.     JMP    SHORT CHECK_SIGN
  58. LOW_CHECK:
  59.     SUB    AX,BX
  60. CHECK_SIGN:
  61.     POP    SI
  62.     OR    SI,SI
  63.     JZ    POSITIVE
  64.     NEG    AX
  65. POSITIVE:
  66.         RET
  67.  
  68. FCMP        ENDP
  69.  
  70.         END
  71.